Data Structures

What is a Complete and Balanced Binary Tree in Data Structure? | Data Structure Tutorial

What is a Complete and Balanced Binary Tree in Data Structure? | Data Structure Tutorial

What is a Complete and Balanced Binary Tree in Data Structure? | Data Structure Tutorial

In this article, you will understand the Complete and Balanced binary tree.

A complete binary tree is a kind of binary tree in which all the levels are entirely filled except possibly the lowest one, which is filled from the left. A complete binary tree is much similar to a full binary tree, but the two major differences are:

  1. Every leaf element must be inclined towards the left.
  2. The last leaf element does not have a right sibling which means a complete binary tree is not a fully binary tree.

Difference between Full Binary Tree Vs Complete Binary Tree

A full Binary Tree is a binary tree in which either it has two children or no children at all but a complete binary tree is a binary tree in which the last leaf has children.

How to create the Complete Binary Tree?

  1. The first element of the array or list is considered the root node. It means several elements on level-I:1.
  2. Put the second element as the left child of the root node and the third element as the right child of the root node. The number of elements on level-II:2.
  3. The next two elements of the list are the children of the left node of the second level. Afterward, put the next two elements as the children of the right node of the second level. The number of elements on level III: 4.
  4. Keep performing the 3rd step until you reach the last element of the list. 

The relationship between the array indexes and tree elements are:

A complete binary tree has a very interesting property that helps in finding the children and parents of any node. 

If the index of any element in the array is j, then the element in the next 2j+1 will become the left child of the tree and the element in the 2j+2 index will become the right child of the tree. Also, the parent of any element at index j is given by the lower bound of (i-1)/2.

Application of Complete Binary Tree

  • It helps in the implementation of heap-based data structures.
  • It helps in the implementation of Heap sort.

Whar is Balanced Binary Tree?

A Balanced Binary Tree is also known as a height-balanced binary tree. It is a kind of binary tree in which the height of the left and right subtree of any node differ by not more than 1. 

The conditions for a height-balanced binary tree:

  • The difference between the left and right subtree for any node of the binary tree is not more than 1.
  • The left subtree is balanced.
  • The right subtree is balanced.

Applications of Balanced Binary Tree

  • AVL Tree
  • Balanced Binary Search Tree
Yamini  Sharma

I am working as a professional engineer in "HIghRadius Technologies Pvt. Ltd." Passionate about learning and exploring new technologies. Enthusiast in writing and sharing what I have in my knowledge bucket.